Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 583 - Prime factors / 583.cpp
blob9f96ba269d51d92768dac8b9d9d41e237b347468
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <sstream>
6 #include <fstream>
7 #include <cassert>
8 #include <climits>
9 #include <cstdlib>
10 #include <cstring>
11 #include <string>
12 #include <cstdio>
13 #include <vector>
14 #include <cmath>
15 #include <queue>
16 #include <deque>
17 #include <stack>
18 #include <map>
19 #include <set>
21 #define D(x) cout << #x " is " << x << endl
23 void funkie(int x){
24 vector<int> p;
25 while (x % 2 == 0) p.push_back(2), x /= 2;
26 for (int d=3; 1LL*d*d <= 1LL*x; d += 2){
27 while (x % d == 0) p.push_back(d), x /= d;
29 if (x > 1) p.push_back(x);
31 printf("%d", p[0]);
32 for (int i=1; i<p.size(); ++i){
33 printf(" x %d", p[i]);
35 puts("");
38 int main(){
39 int n;
40 while (scanf("%d", &n)==1 && n){
41 printf("%d = ", n);
42 if (n < 0) printf("-1 x "), funkie(-n);
43 else funkie(n);
45 return 0;